<!-- +----------------------------------------------------------------------
| 麦沃德科技赋能开发者，助力中小企业发展 
+----------------------------------------------------------------------
| Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
+----------------------------------------------------------------------
| 沃德代驾系统并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
+----------------------------------------------------------------------
| Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
+----------------------------------------------------------------------
| 组件-底部导航 开发者: 麦沃德科技-半夏  
+---------------------------------------------------------------------- -->

<template>
	<view class="component-tab-bar">
		<view class="tab-bar-main" :style="{'--theme-color': themeColor}">
			<view class="main-item wbcentre" v-for="(item, index) in driverTabBarList" :key="index" @click="tabBarPages(item.path)">
				<view class="item-img" :style="{'background-image': 'url('+ item.selectedIconPath +')'}" v-if="item.selectedIconPath && item.path == currentPath"></view>
				<view class="item-img" :style="{'background-image': 'url('+ item.iconPath +')'}" v-else-if="item.iconPath"></view>
				<view class="item-text" :class="{active: item.path == currentPath}" @click.stop="tabBarPages(item.path)">{{ item.name }}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import svgData from "@/common/svg.js"
	export default {
		name: "componentTabBar",
		data() {
			return {
				// 当前页面路径
				currentPath: ""
			}
		},
		computed: {
			driverTabBarList() {
				let list = [{
						path: "/pages/driver/index/index",
						name: "抢单",
						iconPath: svgData.svgToUrl("grab", "#8D929C"),
						selectedIconPath: svgData.svgToUrl("grab", this.$store.state.app.themeColor)
					},
					{
						path: "/pages/driver/order/index",
						name: "订单",
						iconPath: svgData.svgToUrl("order", "#8D929C"),
						selectedIconPath: svgData.svgToUrl("order", this.$store.state.app.themeColor)
					},
					{
						path: "/pages/driver/message/index",
						name: "消息",
						iconPath: svgData.svgToUrl("message", "#8D929C"),
						selectedIconPath: svgData.svgToUrl("message", this.$store.state.app.themeColor)
					},
					{
						path: "/pages/driver/mine/index",
						name: "我的",
						iconPath: svgData.svgToUrl("mine", "#8D929C"),
						selectedIconPath: svgData.svgToUrl("mine", this.$store.state.app.themeColor)
					},
				]
				return list
			},
			themeColor() {
				return this.$store.state.app.themeColor
			},
		},
		mounted() {
			let pages = getCurrentPages();
			this.currentPath = "/" + pages[pages.length - 1].route;
			// #ifndef MP-WEIXIN
			uni.hideTabBar()
			// #endif
		},
		methods: {
			// 跳转底部导航
			tabBarPages(path) {
				if (path == this.currentPath) return
				this.$util.toPage({
					mode: 3,
					path: path
				})
			},
		}
	}
</script>

<style lang="scss">
	.component-tab-bar {
		width: 100%;
		height: 130rpx;

		.tab-bar-main {
			background: #fff;
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			z-index: 998;
			padding-bottom: constant(safe-area-inset-bottom);
			padding-bottom: env(safe-area-inset-bottom);
			display: flex;
			justify-content: space-around;
			border-top: 1rpx solid #F6F7FB;

			.main-item {
				flex: 1;
				display: flex;
				flex-direction: column;
				align-items: center;
				padding: 20rpx 0;

				.item-img {
					width: 60rpx;
					height: 60rpx;
					background-size: 60rpx;
				}

				.item-text {
					color: #8D929C;
					font-size: 20rpx;
					font-weight: 600;
					line-height: 28rpx;
					margin-top: 2rpx;

					&.active {
						color: var(--theme-color);
					}
				}
			}
		}
	}
</style>